import React, { Component } from 'react';
import Axios from 'axios';
import { Toast } from 'antd-mobile';
import './register.scss';
export default class Wode extends Component{
    goback () {
        this.props.history.go(-1);
    }
    constructor(props) {
        super(props);
        this.state = {
            username:"",
            password:""
        }
        this.goregister = this.goregister.bind(this);
        this.gomongodb = this.gomongodb.bind(this);
    }
    goregister(){
        this.props.history.push('../login');
    }
    changeuserName (e) {
       //  console.log(e.target.value);
        this.setState({
            username: e.target.value
        })
    }
    changepassword (e) {
       //  console.log(e.target.value);
        this.setState({
            password: e.target.value
        })
    }
      gomongodb() {
          Axios.post("/api/user/register", { username: this.state.username, password: this.state.password }).then((res) => {
              console.log(res);
             Toast.success(res.data.msg, 1);
          })
      }
    render () {
        return (
            <div className="register">
              <div className="lx-head">
              <i className="iconfont icon-left-angle" onClick={this.goback.bind(this)}></i>
                  <span>注册</span>
                    <span className="lxheadright" onClick={this.goregister}>登录</span>
                </div>
                <div className="formtext" autoComplete="off">
                    <h3>使用手机注册</h3>
                    <div>
                        <input type="text" className="register_input" name="mobile" placeholder="请输入11位手机号" maxLength="11" id="account" value={this.state.username} onChange={this.changeuserName.bind(this)}/>
                    </div>
                    <div>
                        <input type="password" className="register_input" name="password" placeholder="6-16位登录密码" maxLength="16" autoComplete="new-password" value={this.state.password} onChange={this.changepassword.bind(this)}/>
                    </div>
                    <div>
                        <button onClick={this.gomongodb}>注册</button>
                    </div>
                    <div className="register_agreement">点击注册，表示同意 <a href="http://i.jumei.com/m/account/protocol">《聚美优品用户协议》</a></div>
                </div>
            </div>
        )
    }
}
